package qf.sail.controller;


import qf.sail.contents.CodeMsg;
import qf.sail.vo.ResultVO;
import com.alibaba.fastjson.JSON;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class BaseServlet<T> extends HttpServlet {

    protected void repSuccess(HttpServletResponse resp,ResultVO resultVO){
        try {
            resp.getWriter().write(JSON.toJSONString(resultVO));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    protected void repError(HttpServletResponse resp, CodeMsg codeMsg){
        ResultVO resultVO = new ResultVO();
        resultVO.setMsg(codeMsg.getMsg());
        resultVO.setStatus(codeMsg.getCode());
        try {
            resp.getWriter().write(JSON.toJSONString(resultVO));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
